# -*- coding: utf_8 -*-
import random

story_card=[ \
{"name": "Gift", "chinese": u"礼物", "group": "item", "class": "interrupt"},
{"name": "Key", "chinese": u"钥匙", "group": "item", "class": "interrupt"},
{"name": "Tree", "chinese": u"树", "group": "item", "class": "interrupt"},
{"name": "Ring", "chinese": u"指环", "group": "item", "class": "normal"},
{"name": "Door", "chinese": u"门", "group": "item", "class": "normal"},
{"name": "Window", "chinese": u"窗户", "group": "item", "class": "normal"},
{"name": "Spell", "chinese": u"咒语", "group": "item", "class": "normal"},
{"name": "Axe", "chinese": u"斧子", "group": "item", "class": "normal"},
{"name": "Crown", "chinese": u"皇冠", "group": "item", "class": "normal"},
{"name": "Boat", "chinese": u"小船", "group": "item", "class": "normal"},
{"name": "Sword", "chinese": u"剑", "group": "item", "class": "normal"},
{"name": "Food", "chinese": u"食物", "group": "item", "class": "normal"},
{"name": "Fire", "chinese": u"火", "group": "item", "class": "normal"},
{"name": "Book", "chinese": u"书", "group": "item", "class": "normal"},
{"name": "Treasure", "chinese": u"财宝", "group": "item", "class": "normal"},
{"name": "Monster", "chinese": u"怪物", "group": "character", "class": "interrupt"},
{"name": "Horse", "chinese": u"马", "group": "character", "class": "interrupt"},
{"name": "Husband/Wife", "chinese": u"丈夫/妻子", "group": "character", "class": "interrupt"},
{"name": "Orphan", "chinese": u"孤儿", "group": "character", "class": "interrupt"},
{"name": "Frog", "chinese": u"青蛙", "group": "character", "class": "interrupt"},
{"name": "Princess", "chinese": u"公主", "group": "character", "class": "normal"},
{"name": "Beggar", "chinese": u"乞丐", "group": "character", "class": "normal"},
{"name": "Brother/Sister", "chinese": u"兄弟/姐妹", "group": "character", "class": "normal"},
{"name": "Prince", "chinese": u"王子", "group": "character", "class": "normal"},
{"name": "Queen", "chinese": u"皇后", "group": "character", "class": "normal"},
{"name": "King", "chinese": u"国王", "group": "character", "class": "normal"},
{"name": "Giant", "chinese": u"巨人", "group": "character", "class": "normal"},
{"name": "Fairy", "chinese": u"仙女", "group": "character", "class": "normal"},
{"name": "Stepmother", "chinese": u"继母", "group": "character", "class": "normal"},
{"name": "Old Woman", "chinese": u"老婆婆", "group": "character", "class": "normal"},
{"name": "Parent", "chinese": u"父母", "group": "character", "class": "normal"},
{"name": "Witch", "chinese": u"巫婆", "group": "character", "class": "normal"},
{"name": "Thief", "chinese": u"小偷", "group": "character", "class": "normal"},
{"name": "Bird", "chinese": u"小鸟", "group": "character", "class": "normal"},
{"name": "Wolf", "chinese": u"狼", "group": "character", "class": "normal"},
{"name": "Cook", "chinese": u"厨子", "group": "character", "class": "normal"},
{"name": "Shepherdess", "chinese": u"牧羊女", "group": "character", "class": "normal"},
{"name": "Child", "chinese": u"小孩", "group": "character", "class": "normal"},
{"name": "Old Man", "chinese": u"老头", "group": "character", "class": "normal"},
{"name": "Enemy", "chinese": u"敌人", "group": "character", "class": "normal"},
{"name": "Contest", "chinese": u"争论", "group": "event", "class": "interrupt"},
{"name": "Dream", "chinese": u"梦境", "group": "event", "class": "interrupt"},
{"name": "Storm", "chinese": u"暴风雨", "group": "event", "class": "interrupt"},
{"name": "Plan", "chinese": u"计划", "group": "event", "class": "interrupt"},
{"name": "Escape", "chinese": u"逃脱", "group": "event", "class": "normal"},
{"name": "Something is Revealed", "chinese": u"某物显现", "group": "event", "class": "normal"},
{"name": "A Fight", "chinese": u"战斗", "group": "event", "class": "normal"},
{"name": "People Meet", "chinese": u"见面", "group": "event", "class": "normal"},
{"name": "Journey", "chinese": u"旅行", "group": "event", "class": "normal"},
{"name": "A Trap", "chinese": u"圈套", "group": "event", "class": "normal"},
{"name": "An Argument", "chinese": u"争执", "group": "event", "class": "normal"},
{"name": "Someone Is Hurt", "chinese": u"某人受伤", "group": "event", "class": "normal"},
{"name": "A Chase", "chinese": u"追逐", "group": "event", "class": "normal"},
{"name": "Two People Fall In Love", "chinese": u"两人相爱了", "group": "event", "class": "normal"},
{"name": "Time Passes", "chinese": u"时间流逝", "group": "event", "class": "normal"},
{"name": "A Death", "chinese": u"死亡", "group": "event", "class": "normal"},
{"name": "An Object Breaks", "chinese": u"某物破碎", "group": "event", "class": "normal"},
{"name": "Transformation", "chinese": u"变化", "group": "event", "class": "normal"},
{"name": "People Part Company", "chinese": u"分开组队", "group": "event", "class": "normal"},
{"name": "A Rescue", "chinese": u"援救", "group": "event", "class": "normal"},
{"name": "Blind", "chinese": u"盲的", "group": "aspect", "class": "interrupt"},
{"name": "This Item Can Talk", "chinese": u"这个物品会说话", "group": "aspect", "class": "interrupt"},
{"name": "Evil", "chinese": u"邪恶的", "group": "aspect", "class": "interrupt"},
{"name": "Stupid", "chinese": u"愚蠢的", "group": "aspect", "class": "interrupt"},
{"name": "Insane", "chinese": u"精神错乱的", "group": "aspect", "class": "interrupt"},
{"name": "Poisoned", "chinese": u"中毒的", "group": "aspect", "class": "normal"},
{"name": "Sleeping", "chinese": u"睡着的", "group": "aspect", "class": "normal"},
{"name": "Beautiful", "chinese": u"美丽的", "group": "aspect", "class": "normal"},
{"name": "Very Strong", "chinese": u"非常强壮的", "group": "aspect", "class": "normal"},
{"name": "Hidden", "chinese": u"隐藏的", "group": "aspect", "class": "normal"},
{"name": "Very Wise", "chinese": u"非常聪明的", "group": "aspect", "class": "normal"},
{"name": "Secret", "chinese": u"秘密的", "group": "aspect", "class": "normal"},
{"name": "Frightened", "chinese": u"受惊吓的", "group": "aspect", "class": "normal"}, 		
{"name": "Happy", "chinese": u"快乐的", "group": "aspect", "class": "normal"},
{"name": "Far Away", "chinese": u"遥远的", "group": "aspect", "class": "normal"},
{"name": "This Animal Can Talk", "chinese": u"这个动物会说话", "group": "aspect", "class": "normal"},
{"name": "Tiny", "chinese": u"微小的", "group": "aspect", "class": "normal"},
{"name": "Long", "chinese": "Lost", "chinese": u"很久不见的", "group": "aspect", "class": "normal"},
{"name": "Ugly", "chinese": u"丑陋的", "group": "aspect", "class": "normal"},
{"name": "Disguised", "chinese": u"伪装的", "group": "aspect", "class": "normal"},
{"name": "Lucky", "chinese": u"幸运的", "group": "aspect", "class": "normal"},
{"name": "This Can Fly", "chinese": u"这个XX可以飞", "group": "aspect", "class": "normal"},
{"name": "Cursed", "chinese": u"被诅咒的", "group": "aspect", "class": "normal"},
{"name": "Stolen", "chinese": u"偷走了", "group": "aspect", "class": "normal"},
{"name": "Lost", "chinese": u"丢失了", "group": "aspect", "class": "normal"},
{"name": "Stairs", "chinese": u"楼梯", "group": "places", "class": "interrupt"},
{"name": "Kitchen", "chinese": u"厨房", "group": "places", "class": "interrupt"},
{"name": "Home", "chinese": u"家", "group": "places", "class": "interrupt"},
{"name": "Chapel", "chinese": u"教堂", "group": "places", "class": "interrupt"},
{"name": "River", "chinese": u"河", "group": "places", "class": "normal"},
{"name": "Island", "chinese": u"岛", "group": "places", "class": "normal"},
{"name": "Tower", "chinese": u"塔", "group": "places", "class": "normal"},
{"name": "Cottage", "chinese": u"村舍", "group": "places", "class": "normal"},
{"name": "Road", "chinese": u"公路", "group": "places", "class": "normal"},
{"name": "Village", "chinese": u"村庄", "group": "places", "class": "normal"},
{"name": "Ruin", "chinese": u"遗迹", "group": "places", "class": "normal"},
{"name": "Cave", "chinese": u"山洞", "group": "places", "class": "normal"},
{"name": "Town", "chinese": u"城镇", "group": "places", "class": "normal"},
{"name": "Night", "chinese": u"夜晚", "group": "places", "class": "normal"},
{"name": "Mountain", "chinese": u"山脉", "group": "places", "class": "normal"},
{"name": "Kingdom", "chinese": u"王国", "group": "places", "class": "normal"},
{"name": "At Sea", "chinese": u"海上", "group": "places", "class": "normal"},
{"name": "Prison", "chinese": u"监狱", "group": "places", "class": "normal"},
{"name": "Forest", "chinese": u"森林", "group": "places", "class": "normal"},		
{"name": "Palace", "chinese": u"宫殿", "group": "places", "class": "normal"},
]

endding_card =[ \
{"no": 1, "endding": "The King fulfilled his side of the bargain and everyone was happy", "chinese": u"国王履行了约定，每个人都很高兴"},
{"no": 2, "endding": "And he was reunited with his family", "chinese": u"他和他的家人重逢了"},
{"no": 3, "endding": "And so the prophecy had been fulfilled", "chinese": u"预言就这样实现了"},
{"no": 4, "endding": "So she revealed her true identity and they were married", "chinese": u"她表明了她的真实身份，他们结婚了"},
{"no": 5, "endding": "And there they sit to this very day", "chinese": u"就是那一天，他们就坐在那里"},
{"no": 6, "endding": "And to this day no one knows where she ran to", "chinese": u"直到现在，没有人知道她去了哪里"},
{"no": 7, "endding": "So they returned it to its original owner", "chinese": u"于是他们把它还给了它的主人"},
{"no": 8, "endding": "So the queen gave them the prize as she had promised", "chinese": u"皇后给了他们她之前所应承的酬劳"},
{"no": 9, "endding": "And they were blind for the rest of their days for their wickedness and falsehood", "chinese": u"由于他们的邪恶和谎言，他们变瞎了，并这样度过余生"},
{"no": 10, "endding": "So he realized how loyal his brother had been", "chinese": u"他终于了解到他的兄弟是多么的忠诚"},
{"no": 11, "endding": "They looked after it until she was old enough", "chinese": u"他们一直照顾她直到她长大成人"},
{"no": 12, "endding": "And the flames rose higher and the evil place was destroyed", "chinese": u"冲天的火焰烧毁了这个邪恶的地方"},
{"no": 13, "endding": "He saw the error of his ways and repented", "chinese": u"他为他选择了错误的路而悔恨"},
{"no": 14, "endding": "So they escaped their captors and fled home", "chinese": u"他们从捕捉者的手下逃脱了，并逃回了家"},
{"no": 15, "endding": "Which is how the Kingdom got its name", "chinese": u"这就是这个国家名字的由来"},
{"no": 16, "endding": "Her sorrow came to an end and her joy began", "chinese": u"她结束了悲痛并重拾欢颜"},
{"no": 17, "endding": "As dawn broke they could see it was perfect", "chinese": u"破晓时他们可以看到它是完美的"},
{"no": 18, "endding": "His dedication had broken the spell", "chinese": u"他的奉献破除了这个咒语"},
{"no": 19, "endding": "And when they died they passed it on to their children", "chinese": u"他们死后，把它传给了他们的孩子"},
{"no": 20, "endding": "Which proves that a pure heart will always triumph in the end", "chinese": u"这证实了一颗纯洁的心最终总是会取得胜利"},
{"no": 21, "endding": "So the King agreed to spare his life", "chinese": u"因此国王同意赦免他的生命"},
{"no": 22, "endding": "So it was transformed back into human form", "chinese": u"他最后变回了人形"},
{"no": 23, "endding": "They thanked the hero who had saved them all", "chinese": u"他们向拯救了他们的英雄道谢"},
{"no": 24, "endding": "The curse was lifted as had been foretold", "chinese": u"诅咒就像预言所说的那样，消散了"},
{"no": 25, "endding": "True love had broken the enchantment", "chinese": u"真爱破除了魔法"},
{"no": 26, "endding": "And she was reunited with her family", "chinese": u"她和她的家人重逢了"},
{"no": 27, "endding": "So the riddle was finally answered", "chinese": u"这个谜题最终还是找到了答案"},
{"no": 28, "endding": "And never as long as she lived could it be removed", "chinese": u"只要她还活着，它就不能被移除"},
{"no": 29, "endding": "And the parents were reunited with their long-lost daughter", "chinese": u"那对父母和他们久别的女儿重逢了"},
{"no": 30, "endding": "It fit perfectly", "chinese": u"它太适合了，很完美"},
{"no": 31, "endding": "And the King was delighted with such an unusual gift", "chinese": u"国王为这个不寻常的礼物而感到高兴"},
{"no": 32, "endding": "You have freed me from my enchantment and tomorrow we will be married", "chinese": u"“你已经从我的魔法中释放了，而我们明天就要结婚”"},
{"no": 33, "endding": "With the rival dead they could get married at last", "chinese": u"对手死后他们就结婚了"},
{"no": 34, "endding": "But it had vanished as mysteriously as it had appeared", "chinese": u"就像它出现时候一样，它又神秘地消失了"},
{"no": 35, "endding": "And for all I know they could be dancing still", "chinese": u"据我所知，他们到现在还在跳舞"},
{"no": 36, "endding": "But no matter how hard they searched they were never able to find it again", "chinese": u"但是无论他们多努力，他们再也找不到它了"},
{"no": 37, "endding": "Which proves that one should always be more careful of one's companions", "chinese": u"这证明了一个人应该多关心他的同伴"},
{"no": 38, "endding": "So they promised never to fight again", "chinese": u"他们承诺再也不打架了"},
{"no": 39, "endding": "So the spell was broken and they were free", "chinese": u"于是那个魔法被破除了，他们都自由了"},
{"no": 40, "endding": "But she still visited them from time to time", "chinese": u"但是她仍然时常去拜访他们"},
{"no": 41, "endding": "So the evil-doers were thrown down a well", "chinese": u"最后坏人们被丢进了井里"},
{"no": 42, "endding": "So everything was restored to its former glory", "chinese": u"每件东西都恢复成原有的光芒"},
{"no": 43, "endding": "She always wore it to help remind her", "chinese": u"她永远戴着它以提醒自己"},
{"no": 44, "endding": "So he told her he was the prince and they lived happily ever after", "chinese": u"他告诉她自己是个王子，然后他们过着幸福的生活"},
{"no": 45, "endding": "So the village was restored to prosperity", "chinese": u"村庄又恢复了繁荣"},
{"no": 46, "endding": "So the King relented and the two were married", "chinese": u"国王心软了，于是允许他们结婚了"},
{"no": 47, "endding": "They ate it at the feast and it was delicious", "chinese": u"他们在宴会吃它，而且它非常美味"},
{"no": 48, "endding": "She never let it out of her sight again", "chinese": u"她再也不让它离开自己的视线了"},
{"no": 49, "endding": "So the rightful ruler was placed once more on the throne", "chinese": u"那个正直的统治者再次登上了王位"},
{"no": 50, "endding": "He picked up his weapon and went on his way", "chinese": u"他拿起了他的武器，并踏上征途"},
{"no": 51, "endding": "So they changed places and everything was back to normal", "chinese": u"他们改变了地点，所有的事物都恢复了正常"},
{"no": 52, "endding": "And he listened to his mother's advice from then on", "chinese": u"从那以后，他开始听取他母亲的建议了"},
{"no": 53, "endding": "So he forgave her and they were married", "chinese": u"他原谅了她，两人结为了夫妻"},
{"no": 54, "endding": "And the kingdom rejoiced at the end of the tyrant's reign", "chinese": u"整个王国都为暴君统治的结束而庆祝"},
{"no": 55, "endding": "And in the course of time they became King and Queen", "chinese": u"一段时间之后，他们成了国王与王后"},
]

class NO_ENOUGH_CARD(Exception): pass

class Card:
    def __init__(self,cards):
        self.__cards = cards[:]
        self.__rand = random.Random()

    def get_random(self, count=1):
        cards = []
        for i in xrange(count):
            if not len(self.__cards):
                raise NO_ENOUGH_CARD
            index = self.__rand.randint(0, len(self.__cards)-1)
            
            cards.append(self.__cards[index])
            del self.__cards[index]

        return cards

    def append(self, card):
        self.__cards.append(card)

    def __len__(self):
        return len(self.__cards)

def get_story_cards():
    return Card(story_card)

def get_endding_card():
    return Card(endding_card)

def story_card_cmp(x, y):
    if x['group'] == y['group']:
        if x['class'] == y['class']:
            if x['name'] == y['name']:
                return cmp(x['chinese'], y['chinese'])
            else:
                return cmp(x['name'], y['name'])
        else:
            return cmp(x['class'], y['class'])
    else:
        return cmp(x['group'], y['group'])

if __name__ == '__main__':
    story_card.sort(story_card_cmp)
    for i in  story_card:
        print "  ".join([y for x,y in i.items()])

